<!DOCTYPE html>
<html>
<head>
<meta charset="US-ASCII">
<title>The Long Dark</title>
<style> html {overflow: hidden;} *{ width: auto; height: 75%;}</style>
</head>
<body>

		<script src="https://rawgithub.com/mrdoob/three.js/master/build/three.js"></script>

	<script>

      //Function Key Helper From http://nokarma.org/2011/02/27/javascript-game-development-keyboard-input/index.html	

		var Key = {
			  _pressed: {},

			  LEFT: 37,
			  UP: 38,
			  RIGHT: 39,
			  DOWN: 40,
			  
			  isDown: function(keyCode) {
			    return this._pressed[keyCode];
			  },
			  
			  onKeydown: function(event) {
			    this._pressed[event.keyCode] = true;
			  },
			  
			  onKeyup: function(event) {
			    delete this._pressed[event.keyCode];
			  }
		};

		window.addEventListener('keyup', function(event) { Key.onKeyup(event); }, false);
		window.addEventListener('keydown', function(event) { Key.onKeydown(event); }, false);							
					
	  //

        var xres = 200;
        var yres = 150;
        //create scene
			scene = new THREE.Scene();



		//physics list
			var colisionList = [];
			
		//create camera
			var camera = new THREE.PerspectiveCamera(75, xres/yres,  .1, 25);
			camera.position.z = 0;
            camera.position.y = .8;

		//create user
           var userV  =  new THREE.Vector3(0,0,0);
           var userRV  =  new THREE.Vector3(0,0,0);
		//

		//create renderer
			var renderer = new THREE.WebGLRenderer  ();
			renderer.setSize(xres, yres);
			renderer.setClearColor( 0x222222 );
			document.body.appendChild(renderer.domElement);
		//
        
        //add fog
            scene.fog = new THREE.Fog( 0x222222, 1, 10);
        //
        
 ///////create world
         
            
                
            //create floor

                var floorTexture = THREE.ImageUtils.loadTexture('rustytiles02_norm.jpg');
                floorTexture.wrapS = THREE.RepeatWrapping;
                floorTexture.wrapT = THREE.RepeatWrapping;
                floorTexture.repeat.set (3, 300);
                // DoubleSide: render texture on both sides of mesh
                var floorMaterial = new THREE.MeshPhongMaterial( {  color: 0xb0b0b0,  normalMap: floorTexture} );
                var floorGeometry = new THREE.PlaneGeometry(2, 200, 1, 1);
                var floor = new THREE.Mesh(floorGeometry, floorMaterial);



                //flip around and translate
                    floor.rotation.x = - Math.PI / 2 ;
                    scene.add(floor);
                //

            //enalp etaerc

            //create walls

                var wallMaterial = new THREE.MeshPhongMaterial( { color: 0x707070, side: THREE.DoubleSide } );
                var wallGeometry = new THREE.PlaneGeometry(20, 2, 1, 1);
                var wall1 = new THREE.Mesh(wallGeometry, wallMaterial);
                var wall2 = new THREE.Mesh(wallGeometry, wallMaterial);
                
                //rotate & translate
                    wall1.rotation.y = Math.PI /2 ;
                    wall2.rotation.y = Math.PI /2 ;
                    
                    wall1.position.y += 1;
                    wall1.position.x += 1;
                    wall1.position.z -= 10;

                    wall2.position.y += 1;
                    wall2.position.x -= 1;
                    wall2.position.z -= 10;
                // etalsnart & etator

                scene.add(wall1);
                scene.add(wall2);

            //sllaw etarec

            //create ceiling
                
                var ceilingMaterial = new THREE.MeshPhongMaterial( { color: 0xb0b0b0, side: THREE.DoubleSide } );
                var ceilingGeometry = new THREE.PlaneGeometry(40, 2, 1, 1);
                var ceiling = new THREE.Mesh(ceilingGeometry, ceilingMaterial);
                
                ceiling.position = new THREE.Vector3(0,2,-20);
                ceiling.rotation.x += Math.PI / 2;
                ceiling.rotation.z += Math.PI / 2;
                scene.add(ceiling);

            //gniliec etaerc

            //create fluorescents 
                var fluorescentMaterial = new THREE.MeshBasicMaterial( { color: 0xf0ffFa, side: THREE.DoubleSide } );
                var fluorescentGeometry = new THREE.PlaneGeometry(1, .5, 1, 1);
                var arrayFluorescent = new Array();
                var arrayLights = new Array();
                function fluorescentLocationN (n){return -1*( 2 * i +  Math.pow(2,(n+2)*.25));}


                for(var i = 0; i<20; i++)
                {
                    arrayFluorescent[i] = new THREE.Mesh(fluorescentGeometry, fluorescentMaterial); 
                    arrayFluorescent[i].position = new THREE.Vector3(0,1.95,fluorescentLocationN(i));
                    arrayFluorescent[i].rotation.x += Math.PI / 2;
                    
                    
                    arrayLights[i] = new THREE.PointLight(0xf0ffFa, .6, 4);
                    arrayLights[i].position.set(0,1.94,fluorescentLocationN(i));

                    if(i<20)
                    {
                        scene.add(arrayLights[i]);
                    }

                    scene.add(arrayFluorescent[i]);
                    
                }
            //stnecseroulf etaerc

            //user glow
               var userGlow = new THREE.PointLight(0xccccff, .1, 10);
                   userGlow.position.set(0,.6,0);
                    
                   scene.add(userGlow);
            //wolg resu

            //create elluminiation
                var ambientLight = new THREE.AmbientLight( 0x080808, .3);
                scene.add(ambientLight);	
            //noitainimulle etaerc


//////////

//////////
           //load Audio
             // soundFootsteps = new Audio('http://upload.wikimedia.org/wikipedia/commons/3/33/ConstantSpectrumMelody.ogg');
              // soundFootsteps.play(); 

	//function physics User			

       //constants for glow, so as to load only once
            var glowStretch = .1;
            var glowHalfPoint = 40;

		function physicsUser() {
		
		//add volocity


              if (Key.isDown(Key.DOWN))
              {
                     userV.z = .04;
              }
			  else if (Key.isDown(Key.UP))                   
              {
                     userV.z = -.04;
              }
	    	  else
              {
                      userV.z = 0;
              }


              if (Key.isDown(Key.LEFT)) 
              {
			        userRV. y =.03;
              }
              else if (Key.isDown(Key.RIGHT))
              {
                    userRV.y = -.03;
              }
              else 
              {
                  userRV.y = 0; 
		      }
        //apply friction
           //userV.multiply(new THREE.Vector3(.01,.01,.01));
          // userRV.multiply(new THREE.Vector3(.01,.01,.01));
        //

		//check collisions
		
		//subtract appropriatly
		
		//move 
           userGlow.rotateY(userRV.y);
           userGlow.translateZ(userV.z);
           camera.rotateY(userRV.y);	
	       camera.translateZ(userV.z);					
        //user glow increase glow
           
           userGlow.intensity =  ((glowStretch * (-1 * userGlow.position.z - glowHalfPoint)) / (1 + Math.abs(glowStretch * (-1 * userGlow.position.z - glowHalfPoint))*2)) + .5;   

		}
	//

	//function render				
		var render = function () {
		
			requestAnimationFrame(render);
				
	
            physicsUser();

			renderer.render(scene, camera);
				
		};
	//
	
			render();
	//	
		
		</script>
</body>
</html>
